package recyclerview.zjitc.net.recyclerview;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * @author 朱志文
 * @data 2019/11/2 0002
 */
public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.MyViewHolder> {
    private List<String> mList_title;
    private List<String> mList_content;
    private List<Integer> mList_image;
    private Context mContext;

    public HomeAdapter(List<String> mList_title, List<String> mList_content, List<Integer> mList_image, Context mContext) {
        this.mList_title = mList_title;
        this.mList_content = mList_content;
        this.mList_image = mList_image;
        this.mContext = mContext;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.list_item, viewGroup, false);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) {
        myViewHolder.item_titles.setText(mList_title.get(i));
        myViewHolder.item_content.setText(mList_content.get(i));
        myViewHolder.item_iv.setBackgroundResource(mList_image.get(i));
    }

    @Override
    public int getItemCount() {
        return mList_title.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView item_titles;
        TextView item_content;
        ImageView item_iv;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            item_titles = itemView.findViewById(R.id.item_titles);
            item_content = itemView.findViewById(R.id.item_content);
            item_iv = itemView.findViewById(R.id.item_iv);
        }
    }
}
